﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using V5_EShop._Class.BLL;
using V5_BLL;
using System.Data;
using V5_Common;

namespace V5_EShop._Class.Data {
    public class V5GZProductHelper : IV5Helper {
        private static readonly V5GZProductHelper m_Instance = new V5GZProductHelper();
        /// <summary>
        /// 
        /// </summary>
        public static V5GZProductHelper Instance {
            get { return m_Instance; }
        }
        private HtmlString _Pager = new HtmlString("");

        public HtmlString Pager {
            get { return _Pager; }
            set { _Pager = value; }
        }


        private BLLGZProduct bllGZProduct = new BLLGZProduct();
        private BLLGZProductClass bllGZProductClass = new BLLGZProductClass();


        public DataTable Query_By(string what, string where, string orderby, int limit) {
            return bllGZProduct.GetList(what, limit, where, orderby).Tables[0];
        }

        public DataTable Query_By_List(string what, string where, string orderby, int limit) {
            return bllGZProductClass.GetList(what, limit, where, orderby).Tables[0];
        }

        public DataTable Query_By_Pager(string what, string where, string orderby, int limit, int pageIndex, string UrlList) {
            int RecordCount = 0;
            DataTable dtPager = bllGZProduct.GetList(what, limit, pageIndex, where, orderby, ref RecordCount).Tables[0];
            Easp.Pager.RecordCount = RecordCount;
            Easp.Pager.CurrentPageIndex = pageIndex;
            Easp.Pager.PageSize = Easp.Str.SetNumber(limit); ;
            Easp.Pager.PageUrlFormat = UrlList.Replace("@pageid@", "{0}");
            this.Pager = new HtmlString(Easp.Pager.Display());
            return dtPager;
        }

        public DataRow Get_By(string ID) {
            using (DataTable dt = bllGZProduct.GetList(" And ID='" + ID + "'").Tables[0]) {
                if (dt != null && dt.Rows.Count > 0) {
                    return dt.Rows[0];
                }
                return null;
            }
        }

        public DataRow Get_By_List(string ClassID) {
            using (DataTable dt = bllGZProductClass.GetList(" And ID='" + ClassID + "'").Tables[0]) {
                if (dt != null && dt.Rows.Count > 0) {
                    return dt.Rows[0];
                }
                return null;
            }
        }

        public string UrlView(object attributes) {
            return string.Empty;
        }

        public string UrlList(object attributes) {
            return string.Empty;
        }

    }
}